@extends('layouts.buz.layout', ['header_active' => 'statistic'])
@section('title')
    统计分析 - 通道统计
@endsection()

@section('full-content')

    @include('layouts.buz.sidebar.statistic', ['active'=> 'payment'])

    <div class="yhy-member col-sm-9 col-sm-push-3 col-md-10 col-md-push-2 col-xs-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    各通道充值统计
                </h4>
            </div>
            <div class="panel-body">

                <div class="row y-mt60">
                    <div class="col-sm-12 col-md-12 lineH28">

                        <div class="col-sm-3 col-md-3">
                            <input  type="text" id="starttime" value="{{date('Y-m-d 00:00')}}" class="form_datetime form-control" style="width: 100%;">
                        </div>
                        <div class="col-sm-3 col-md-3 padd">
                            <input  type="text" id="endtime" value="{{date('Y-m-d 23:59')}}" class="form_datetime form-control" >
                        </div>
                        <div class="col-sm-3 col-md-3">
                            <div class="form-group">
                                <label for="lastname" class="col-sm-5 col-md-5 padd control-label" >通道类型</label>
                                <div class="col-sm-7 col-md-7 padd">
                                    <select class="form-control" id="chanleType">
                                        <option value="all">全部</option>
                                        <option value="weixin">微信扫码</option>
                                        <option value="alipay">支付宝扫码</option>
                                        <option value="qq">QQ扫码</option>
                                        <option value="bank">在线银行</option>
                                        <option value="weixin_wap">微信wap</option>
                                        <option value="alipay_wap">支付宝wap</option>
                                        <option value="qq_wap">QQ钱包WAP</option>
                                        <option value="bank_wap">银联在线</option>
                                        {{--<option value="weixin_sdk">微信SDK</option>--}}
                                        {{--<option value="alipay_sdk">支付宝SDK</option>--}}
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-2 col-md-2">
                            <button type="button" class="btn btn-primary" id="search" onclick="SearchData()">查询</button>
                        </div>
                    </div>
                </div>
                <div class="historyList">
                    <table class="table table-striped table-bordered" id="table">
                    </table>

                </div>
            </div>
        </div>
    </div>
@endsection()

@section('dialog')
    <div class="modal fade in"  tabindex="-1" role="dialog" id="loginModel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <h4 class="text-center">token超时，请重新登录</h4>
                </div>
                <div class="modal-footer text-xs-center">
                    <button type="button" class="btn btn-danger" id="replayLogin">重新登录</button>
                </div>
            </div>
        </div>
    </div>

@endsection()
@section('bottom_js')
    <script>
        $(function () {
            $("#replayLogin").click(function () {
                window.location.href="/login";
            })
        })

        //时间
        $(".form_datetime").datetimepicker({
            language: 'zh-CN',
            format: "yyyy-mm-dd hh:ii",
            autoclose: true,
            todayBtn: true,
            minView: 1,
            inline: true
        });

        $(function () {
            $("#starttime").datetimepicker({
                todayBtn : "linked",
                autoclose: true,
            }).on('changeDate',function(e){
                var startTime = e.date;
                $('#endtime').datetimepicker('setStartDate',startTime);
            });
            $("#endtime").datetimepicker({
                todayBtn : "linked",
                autoclose: true,
            }).on('changeDate',function(e){
                var endTime = e.date;
                $('#starttime').datetimepicker('setEndDate',endTime);
            });
            $('#table').bootstrapTable({
                url: '/api/statistic/payments',
                queryParamsType: '',              //默认值为 'limit' ,在默认情况下 传给服务端的参数为：offset,limit,sort
                queryParams: queryParams,
                method: "get",
                pagination: false,
                sidePagination: "server",         //分页方式：client客户端分页，server服务端分页（*）
                striped: true,                    //是否显示行间隔色
                cache: false,
                uniqueId: "id",               //每一行的唯一标识，一般为主键列
                height:700,
                paginationPreText: "上一页",
                paginationNextText: "下一页",
                onLoadSuccess: function(data){  //加载成功时执行
                },
                responseHandler: function(res) {
                    if(filterAjaxData(res)){
                        return {
                            // "total": res.data.total,//总页数
                            "rows": res.data  //数据
                        };
                    }
                    return {
                        "total": 0,//总页数
                        "rows": []  //数据
                    };

                },
                columns: [
//                    { checkbox: true },
                    { title: '通道名称', field: 'p_name' },
                    { title: '通道订单数', field: 't_orders' },
                    { title: '成功订单数', field: 'd_orders' },
                    { title: '总提交金额', field: 't_amt'},
                    { title: '成功金额', field: 'd_amt' },
                    { title: '商户收入', field: 'income' },
                ],
            });
        })
        //查询条件
        function queryParams(params) {
            return {
                pageSize: params.pageSize,
                page: params.pageNumber,
                start_at: $("#starttime").val(),
                end_at: $("#endtime").val(),
                payment: $("#chanleType").val(),
                order_status:$("#orderStatus").val(),
                merchant_no:$("#orderNo").val(),
            };
        }
        function SearchData() {
            //判断时间
            var starttime=$("#starttime").val();
            var endtime=$("#endtime").val();
            if(starttime==null||endtime==null){
                //setTimeout(function () {
                showMsg("时间不能为空");
                //}, 230);
                return false;
            }
            //判断时间的大小
//            var ts1 = Date.parse(starttime.replace(/-/g, '/ '));
//            var ts2 = Date.parse(endtime.replace(/-/g, '/ '));
//            var ts = ts2-ts1;
//            console.log(ts);
//            if(ts<=0){
//                showMsg("截止时间小于开始时间，请重新选择！");
//                return false;
//            }
            $('#table').bootstrapTable('refreshOptions', { pageNumber: 1 });
        }

    </script>
@endsection()
